package com.dtx.demo;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

public class Animal {

    public Integer age;

    public String name;

    public void walk(){
        System.out.println("动物走路");
    }

    public void eat(){
        System.out.println("动物吃东西");
    }

    public static void main(String[] args) throws NoSuchMethodException, InvocationTargetException, IllegalAccessException, InstantiationException {
        Animal animal = new Person();
        Class<? extends Animal> c1 = animal.getClass();
        Method playComputer = c1.getDeclaredMethod("playComputer");
        String name = playComputer.getName();
        System.out.println(name);
        playComputer.invoke(animal);
        
    }
}

class Person extends Animal{

    @Override
    public void eat() {
        System.out.println("人类吃东西");
    }

    @Override
    public void walk() {
        System.out.println("人类走路");
    }

    public void playComputer(){
        System.out.println("人类玩电脑");
    }
}
